11 - OAuth (5) Client credentials grant

今天來看看 OAuth 最後一種 grant,Client credentials grant,的 request & response
由於 Client 不需要取得使用者的授權,因此可以直接向 Authorization server 發出 POST 請求。另一方面,由於 Authorization server 不需要驗證使用者,只要確認 Client 的 credential 即可(譬如使用 key)
POST /token
Content-Type: application/x-www-form-urlencoded
{
  grant_type: client_credential,
  scope: xxx,
  resource: xxx
}
grant_type: 這裡使用 "client_credential" 代表我們要使用 OAuth Client credentials grantscope: 代表這個請求所想要取得授權的內容,譬如 get:dataresource: 在 Authorization server 所登記的 Resource server 的 IDAuthorization server 收到 Client 的請求之後,就會回傳 response 給 Client,當中包含 access token。
{
  access_token: xxx,
  token_type: xxx
}
這個狀況下沒有使用者的參與,是純粹的後端 api 溝通,而且基本上每次請求資源的時候,都可以再次拿到新的 access token,因此不需要使用 refresh token。